#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <fcntl.h>

#include "lp_global_vars.h"
//------------------------------------------------------------------------------
int create_udp_server_socket(char ip[STRING_SIZE], int port, struct sockaddr_in* addr) {
	int sid;

	sid = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

	addr->sin_family = AF_INET;
	addr->sin_port = htons(port);
	addr->sin_addr.s_addr = inet_addr(ip);

	int e = bind(sid, (struct sockaddr*) addr, sizeof(struct sockaddr_in));
	assert(e != -1);
	return sid;
}
//------------------------------------------------------------------------------
int create_udp_client_socket(char ip[STRING_SIZE], int port, struct sockaddr_in* addr) {
	int sid;
	sid = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
	addr->sin_family = AF_INET;
	addr->sin_port = htons(port);
	addr->sin_addr.s_addr = inet_addr(ip);

	return sid;
}
//------------------------------------------------------------------------------


